let jwt = require('jsonwebtoken');
module.exports = {

    //生成
    sign: ({ username, _id }) => jwt.sign({ username, _id }, 'luge', { expiresIn: 60 * 60 * 24 }),


    //解密
    verify: token => new Promise((resolve, reject) => {
        jwt.verify(token, 'luge', (err, decode) => {
            if (!err) {
                resolve(decode)
            } else {
                reject(err.message) //message错误描述
            }
        })
    })
}